import { resetRouter } from '@/router'
import {trace} from "../../utils/trace"
import {
  charge,
  coupon, couponQuery,
  invoice,
  invoiceDetail,
  invoiceQuery, invoiceStatus, invoiceTransport,
  queryCharge,
  refund, refundDetail,
  refundQuery, seoQuery
} from '../../api/finance'

const getDefaultState = () => {
  return {
    invoiceList:[],
  }
}

const state = getDefaultState()

const mutations = {

  SET_LIST: (state, invoiceList) => {
    state.invoiceList = invoiceList
  },
}

const actions = {
  // 优惠券-发放
  coupon({ commit }, data) {
    return new Promise((resolve, reject) => {
      coupon(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 申请开发票 invoice
  invoice({ commit }, data) {
    return new Promise((resolve, reject) => {
      invoice(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 审核发票的状态 invoiceStatus
  invoiceStatus({ commit }, data) {
    return new Promise((resolve, reject) => {
      invoiceStatus(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取发票的详细信息 invoiceDetail
  invoiceDetail({ commit }, data) {
    return new Promise((resolve, reject) => {
      invoiceDetail(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取发票的列表 invoiceQuery
  invoiceQuery({ commit }, data) {
    return new Promise((resolve, reject) => {
      invoiceQuery(data).then(response => {
        const { data } = response;
        commit("SET_LIST",data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // 更新审核通过的物流信息 invoiceTransport
  invoiceTransport({ commit }, data) {
    return new Promise((resolve, reject) => {
      invoiceTransport(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // 充值
  charge({ commit }, data) {
    return new Promise((resolve, reject) => {
      charge(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },


  // 充值记录查询   queryCharge
  queryCharge({ commit }, data) {
    return new Promise((resolve, reject) => {
      queryCharge(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 消费记录  queryRecord
  seoQuery({ commit }, data) {
    return new Promise((resolve, reject) => {
      seoQuery(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 退款申请 refund
  refund({ commit }, data) {
    return new Promise((resolve, reject) => {
      refund(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新退款结果 refundResult
  refundResult({ commit }, data) {
    return new Promise((resolve, reject) => {
      refundResult(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 查询退款列表  refundQuery
  refundQuery({ commit }, data) {
    return new Promise((resolve, reject) => {
      refundQuery(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 查询退款详情  refundDetail
  refundDetail({ commit }, data) {
    return new Promise((resolve, reject) => {
      refundDetail(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 优惠券-查询列表  couponQuery
  couponQuery({ commit }, data) {
    return new Promise((resolve, reject) => {
      couponQuery(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },





}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}


